/*
package com.poi.java.controller;

import com.poi.java.dao.TableDao;
import com.poi.java.util.DayCompare;
import com.poi.java.util.FileUtil;
import com.poi.java.util.MoneyToChiness;
import com.poi.java.util.WordUtils;
import com.poi.java.v.tID;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


@RestController
@RequestMapping("/word1")
public class WordController1 {

    @Resource
    private TableDao tableDao;


    @PostMapping("/createNewWord1")
    public  Object createNewWord(@RequestBody tID tid) throws ParseException, IOException {
        return getresult(tid,true);
    }

//    @PostMapping("/count")
//    public  Object count(@RequestBody tID tid) throws ParseException, IOException {
//        return getresult(tid,false);
//    }

    private Object getresult(tID tid,boolean wordflag) throws ParseException, IOException {
        DecimalFormat df4 = new DecimalFormat("######0.0000");
        Map<String,String> totalMap = new HashMap();

        List<Map<String,Object>> landProject= tableDao.land_project(tid.getLand_project()); //一、估价项目名称：数据来源land_project
        toMap(totalMap,landProject.get(0), "");
//        Map<String,Object> coblp=tableDao.coblp(tid.getCoblp());//1、地价内涵：数据来源coblp
//        toMap(totalMap,tableDao.appraiser(tid.getAppraiser()), "");//土地估价师签字：数据来源appraiser，
//        toMap(totalMap,tableDao.guidance_document(tid.getGuidance_document()), "");//5.3.受托方掌握的有关资料：数据来源guidance_document
//        toMap(totalMap,coblp, "");

//        Map<String,Object> land_material=tableDao.land_material(tid.getLand_material());//表7
//        Map<String,Object> land_case=tableDao.land_case(tid.getLand_case());
//        toMap(totalMap,tableDao.base_land_price(tid.getBase_land_price()), "");

//        toMap(totalMap,tableDao.industry_priceindex(tid.getIndustry_priceindex()), "");
//        toMap(totalMap,tableDao.land_case(tid.getLand_case()), "");
//        toMap(totalMap,land_material);
//        toMap(totalMap,tableDao.land_temp(tid.getLand_temp()), "");
//        toMap(totalMap,tableDao.rr_price(tid.getRr_price()), "");


        if (landProject.get("gjs1") != null) {
            Map<String,Object>appraiser =tableDao.appraiser(Integer.parseInt(landProject.get("gjs1").toString()));
            if (appraiser == null){
                toMapForStr(totalMap,"appraiser_number1","");
            }else {
                toMapForStr(totalMap,"gjs1",appraiser.get("name"));
                toMapForStr(totalMap,"appraiser_number1",appraiser.get("number"));
            }

        }
        if (landProject.get("gjs2") != null) {
            Map<String,Object> appraiser = tableDao.appraiser(Integer.parseInt(landProject.get("gjs2").toString()));
            if (appraiser ==null){
                toMapForStr(totalMap,"appraiser_number2","");
            }else {
                toMapForStr(totalMap,"gjs2",appraiser.get("name"));
                toMapForStr(totalMap,"appraiser_number2",appraiser.get("number"));
            }
        }


//      表7 {"id": 1111111111111  ,"id1":"","id2":"","id3":"" }

        HashMap<String,Integer> material = tid.getLand_material();
        Map<String,Object> mater =null;
        for (String key :material.keySet()){
            switch (key){
                case "id1":
                    mater =tableDao.land_case(material.get(key));//表7
                    toMap(totalMap, mater,"1"); //表7
                case "id2":
                    mater =tableDao.land_case(material.get(key));//表7

                    toMap(totalMap, mater,"2"); //表7
                case "id3":
                    mater =tableDao.land_case(material.get(key));//表7
                    //表7
                    toMap(totalMap, mater,"3"); //表7
                    break;
                default:
                    mater =tableDao.land_material(material.get(key));//表7
                    toMap(totalMap, mater,""); //表7
                    break;
            }

            String year  = mater.get("jy_date").toString().split("-")[0];//交易时间
            String month  = mater.get("jy_date").toString().split("-")[1];

            String infra_des1 = mater.get("infra_des").toString();
            String infra_des ="";

            switch (infra_des1){
                case "五通":
                    infra_des = "通路、通讯、通电、供水、排水";
                    break;
                case "六通":
                    infra_des = "通路、通讯、通电、通燃气、供水、排水";
                    break;
                case "七通":
                    infra_des = "通路、通讯、通电、通燃气、供水、排雨水、排污水";
                    break;
            }


            totalMap.put("yearn","");
            totalMap.put("quarter","");
            totalMap.put("yearn1","");
            totalMap.put("quarter1","");
            //根据年份和季度去库中找数据
            String quarter1PIndex = tableDao.industry_priceindex(Integer.parseInt(year),1);
            String yearn1 ="";
            String price_index_last =quarter1PIndex;
            if (quarter1PIndex == null){
                quarter1PIndex ="-";
                totalMap.put("yearn",year);
                totalMap.put("quarter","1");
                //等于上个季度
                totalMap.put("quarter1","1");
                yearn1 =year;
                price_index_last =quarter1PIndex;
            }
            String quarter2 = tableDao.industry_priceindex(Integer.parseInt(year),2);
            if (quarter2 == null){
                quarter2 ="-";
                totalMap.put("yearn",year);
                totalMap.put("quarter","2");
                //等于上个季度
                totalMap.put("quarter1","1");
                yearn1 =year;
                price_index_last =quarter1PIndex;
            }
            String quarter3 = tableDao.industry_priceindex(Integer.parseInt(year),3);
            if (quarter3 == null){
                quarter3 ="-";
                totalMap.put("yearn",year);
                totalMap.put("quarter","3");
                //等于上个季度
                totalMap.put("quarter1","2");
                yearn1 =year;
                price_index_last =quarter2;
            }
            String quarter4 = tableDao.industry_priceindex(Integer.parseInt(year),4);
            if (quarter4 == null){
                quarter4 ="-";
                totalMap.put("yearn",year);
                totalMap.put("quarter","4");
                //等于上个季度
                totalMap.put("quarter1","3");
                yearn1 =year;
                price_index_last =quarter3;

            }
            //等于上个季度
            totalMap.put("yearn1",yearn1);
            totalMap.put("price_index_last",price_index_last);

            //月份所在的季度
            String quarter="";
            switch (month){
                case "01":
                case "02":
                case "03":
                    quarter = quarter1PIndex;
                    break;
                case "04":
                case "05":
                case "06":
                    quarter = quarter2;
                    break;
                case "07":
                case "08":
                case "09":
                    quarter = quarter3;
                    break;
                default:
                    quarter = quarter4;
                    break;
            }

            //表11
            double ra_n = 100.0;
            double fs_n = 100.0;
            double highway_n = 100.0;
            double icd_n = 100.0;
            double land_n = 100.0;
            double shape_n = 100.0;
            double sr_n = 100.0;
            double src_n = 100.0;

            String ra_regex = tid.getOthers().get("ra_regex").toString();
            String fs_regex = tid.getOthers().get("fs_regex").toString();
            String highway_regex = tid.getOthers().get("highway_regex").toString();
            String icd_regex = tid.getOthers().get("icd_regex").toString();
            String area_regex = tid.getOthers().get("area_regex").toString();
            String shape_regex = tid.getOthers().get("shape_regex").toString();
            String sr_regex = tid.getOthers().get("sr_regex").toString();
            String src_regex = tid.getOthers().get("src_regex").toString();

            //表11
            Map<String,Object> material1 =  tableDao.land_material(Integer.parseInt(tid.getLand_material().get("id").toString()));
                ra_n = 100 + (getJb(mater,"ra_n") - getJb(material1,"ra_n"))*Double.valueOf(ra_regex);
            fs_n = 100 + (getJb(mater,"fs_n") - getJb(material1,"fs_n"))*Double.valueOf(fs_regex);
            highway_n = 100 + (getJb(mater,"highway_n") - getJb(material1,"highway_n"))*Double.valueOf(highway_regex);
            icd_n = 100 + (getJb(mater,"icd_n") - getJb(material1,"icd_n"))*Double.valueOf(icd_regex);
            land_n = 100 + (getJb(mater,"land_n") - getJb(material1,"land_n"))*Double.valueOf(area_regex);
            shape_n = 100 + (getJb(mater,"shape_n") - getJb(material1,"shape_n"))*Double.valueOf(shape_regex);
            sr_n = 100 + (getJb(mater,"sr_n") - getJb(material1,"sr_n"))*Double.valueOf(sr_regex);
            src_n = 100 + (getJb(mater,"src_n") - getJb(material1,"src_n"))*Double.valueOf(src_regex);

            switch (key){
                case "id1"://案例表
                    //  表8(industry_priceindex)期日数据根据表(案例表或者素材表)的交易时间的年来查，查这一年每个季度的工业地价指数industry_priceindex，
//                      如果当前季度有就放进去，没有就（—）一个横杠，表8的工业地价指数是上边期日数据库对应的数据
                    toMapForStr(totalMap,"year1",year);

                    toMapForStr(totalMap,"price_index1",quarter1PIndex);
                    toMapForStr(totalMap,"price_index2",quarter2);
                    toMapForStr(totalMap,"price_index3",quarter3);
                    toMapForStr(totalMap,"price_index4",quarter4);

                    toMapForStr(totalMap,"ra_n1",df4.format(ra_n));
                    toMapForStr(totalMap,"fs_n1",fs_n);
                    toMapForStr(totalMap,"highway_n1",highway_n);
                    toMapForStr(totalMap,"icd_n1",icd_n);
                    toMapForStr(totalMap,"landn_mj1",land_n);
                    toMapForStr(totalMap,"shape_n1",shape_n);
                    toMapForStr(totalMap,"sr_n1",sr_n);
                    toMapForStr(totalMap,"src_n1",df4.format(src_n));

                    toMapForStr(totalMap,"price_index14",quarter);
                    totalMap.put("infra_des1",infra_des);

                    break;
                case "id2"://案例表
                    toMapForStr(totalMap,"year2",year);

                    toMapForStr(totalMap,"price_index5",quarter1PIndex);
                    toMapForStr(totalMap,"price_index6",quarter2);
                    toMapForStr(totalMap,"price_index7",quarter3);
                    toMapForStr(totalMap,"price_index8",quarter4);


                    toMapForStr(totalMap,"ra_n2",ra_n);
                    toMapForStr(totalMap,"fs_n2",fs_n);
                    toMapForStr(totalMap,"highway_n2",highway_n);
                    toMapForStr(totalMap,"icd_n2",icd_n);
                    toMapForStr(totalMap,"landn_mj2",land_n);
                    toMapForStr(totalMap,"shape_n2",shape_n);
                    toMapForStr(totalMap,"sr_n2",sr_n);
                    toMapForStr(totalMap,"src_n2",src_n);
                    totalMap.put("infra_des2",infra_des);
                    toMapForStr(totalMap,"price_index15",quarter);
                    break;
                case "id3"://案例表
                    toMapForStr(totalMap,"year3",year);
                    toMapForStr(totalMap,"price_index9",quarter1PIndex);
                    toMapForStr(totalMap,"price_index10",quarter2);
                    toMapForStr(totalMap,"price_index11",quarter3);
                    toMapForStr(totalMap,"price_index12",quarter4);

                    toMapForStr(totalMap,"ra_n3",ra_n);
                    toMapForStr(totalMap,"fs_n3",fs_n);
                    toMapForStr(totalMap,"highway_n3",highway_n);
                    toMapForStr(totalMap,"icd_n3",icd_n);
                    toMapForStr(totalMap,"landn_mj3",land_n);
                    toMapForStr(totalMap,"shape_n3",shape_n);
                    toMapForStr(totalMap,"sr_n3",sr_n);
                    toMapForStr(totalMap,"src_n3",src_n);
                    totalMap.put("infra_des3",infra_des);
                    toMapForStr(totalMap,"price_index16",quarter);

                default:  //素材表
                    toMapForStr(totalMap,"year",year);

                    toMapForStr(totalMap,"ra_n",ra_n);
                    toMapForStr(totalMap,"fs_n",fs_n);
                    toMapForStr(totalMap,"highway_n",highway_n);
                    toMapForStr(totalMap,"icd_n",icd_n);
                    toMapForStr(totalMap,"land_mjn",land_n);
                    toMapForStr(totalMap,"shape_n",shape_n);
                    toMapForStr(totalMap,"sr_n",sr_n);
                    toMapForStr(totalMap,"src_n",src_n);
                    totalMap.put("infra_des",infra_des);
                    toMapForStr(totalMap,"price_index13",quarter);

                    //${price_index_next}按指导文件估价期日
                    String region_name = mater.get("regin").toString();//素材表区域
                    Map<String,Object> guidance= tableDao.guidance_document(region_name).get(0);
                    String announcementDate  = guidance.get("announcement_date").toString().split("-")[1];
                    //月份所在的季度
                    String price_index_next="";
                    switch (announcementDate){
                        case "01":
                        case "02":
                        case "03":
                            price_index_next = quarter1PIndex;
                            break;
                        case "04":
                        case "05":
                        case "06":
                            price_index_next = quarter2;
                            break;
                        case "07":
                        case "08":
                        case "09":
                            price_index_next = quarter3;
                            break;
                        default:
                            price_index_next = quarter4;
                            break;
                    }

                    totalMap.put("price_index_next",price_index_next);
                    break;
          }
        }

        String region_name = totalMap.get("regin").toString();//素材表区域
        totalMap.put("region",region_name);//word和数据库不一致
        //5.3.受托方掌握的有关资料：数据来源guidance_document
        toMap(totalMap,tableDao.guidance_document(region_name).get(0), "");

        //表13
        List<Map<String,Object>> coblpbyRegin = tableDao.coblpbyRegin(region_name);
        int index =20;
        for (int j =0;j<coblpbyRegin.size();j++){
            String strcode = j ==0?"":String.valueOf(j);
            toMap(totalMap,coblpbyRegin.get(j),strcode);

            Map<String,Object> coblp = coblpbyRegin.get(j);
            List<Map<String,Object>> ratioList= tableDao.plot_ratio(coblp.get("price_define").toString(),region_name,coblp.get("usetype").toString());

            toMap(totalMap,ratioList.get(0),strcode);
            //容错 word中和数据库字段名不一致
            toMapForStr(totalMap,"coblp_date",ratioList.get(0).get("date"));
            toMapForStr(totalMap,"coblp_ratio",ratioList.get(0).get("plot_ratio"));

            int temp = index+j;
            for (int i = 0;i<ratioList.size();i++){
                toMapForStr(totalMap,"plot_ratio".concat(String.valueOf(temp)),ratioList.get(i).get("plot_ratio"));
                temp = temp +4;
            }

        }

        //表14是通过素材表（land_material表）选择的素材的区域和等级来判断展示（wz_ccoblp||xc_ccoblp||gs_ccoblp）这三张表哪张表的数据，三张表字段现在用到的数据字段是一样的
        String use_level   = totalMap.get("use_level").toString();
        List<Map<String,Object>> datas = new ArrayList<Map<String,Object>>();
        switch (region_name) {
            case "f"://表14就展示wz_ccoblp
                datas =tableDao.wz_ccoblp(Integer.parseInt(use_level));
                break;
            case "相城区"://表14就展示xc_ccoblp
                datas = tableDao.xc_ccoblp(Integer.parseInt(use_level));
                break;
            case "其他区"://表14就展示gs_ccoblp
                datas = tableDao.gs_ccoblp(Integer.parseInt(use_level));
                break;
        }
        toMap(totalMap,datas.get(0),"");
        toMap(totalMap,datas.get(1),"1");f
        toMap(totalMap,datas.get(2),"2");
        toMap(totalMap,datas.get(3),"3");
        toMap(totalMap,datas.get(4),"4");

        Double tb16_sum = Double.valueOf(totalMap.get("ra_rate").toString())+
                Double.valueOf(totalMap.get("highway_rate").toString())+
                Double.valueOf(totalMap.get("fs_rate").toString())+
                Double.valueOf(totalMap.get("icd_rate").toString())+
                Double.valueOf(totalMap.get("rr_rate").toString())+
                Double.valueOf(totalMap.get("rl_rate").toString())+
                Double.valueOf(totalMap.get("sr_type").toString())+
                Double.valueOf(totalMap.get("sr_condi").toString())+
                Double.valueOf(totalMap.get("land_shape").toString())+
                Double.valueOf(totalMap.get("land_mj").toString())+
                Double.valueOf(totalMap.get("al_type").toString())+
                Double.valueOf(totalMap.get("terrain_condi").toString());
        Double.valueOf(totalMap.get("plan_limit").toString());
        Double.valueOf(totalMap.get("infra_rate").toString());
        Double.valueOf(totalMap.get("nature_rate").toString());

//     表 16
        toMapForStr(totalMap,"tb16_sum",df4.format(tb16_sum));
//     表 19
        Map<String,Object> rr_price   = tableDao.rr_price(region_name);
        toMap(totalMap,rr_price,"");

        int tab19_sum = Integer.parseInt(rr_price.get("r_price").toString())+
                Integer.parseInt(rr_price.get("e_price").toString())+
                Integer.parseInt(rr_price.get("w_price").toString())+
                Integer.parseInt(rr_price.get("s_price").toString())+
                Integer.parseInt(rr_price.get("c_price").toString())+
                Integer.parseInt(rr_price.get("g_price").toString())+
                Integer.parseInt(rr_price.get("l_price").toString());
        toMapForStr(totalMap,"tab19_sum",df4.format(tab19_sum));
        int tab19_xiuzheng  =  (~(Integer.parseInt(rr_price.get("g_price").toString()) - 1));;
        toMapForStr(totalMap,"tab19_xiuzheng",String.valueOf(tab19_xiuzheng));

        // 1.计算1 land_outyearn = 素材表land_outyear减去value_date
        DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
        String land_outyearn = yearCompare(format1.parse(totalMap.get("out_year").toString()),format1.parse(landProject.get("value_date").toString()));
        toMapForStr(totalMap,"land_outyearn",land_outyearn);

//      2.计算2 K2＝{1－[1/（1+r）m] }/{1－[1/（1+r）n] }=#k2#。
        Double r = 5.4;
        int n=50;
        double m = Double.valueOf(land_outyearn);

        double k2 = (1-(1 / Math.pow(1 + r, m)) )/(1- (1 / Math.pow(1 + r, n)));
        toMapForStr(totalMap,"k2",df4.format(k2));


        //表10
//     3.计算  K=1-1/(1+r)n
        double tb_1 = 1-1/Math.pow(1+r,Double.valueOf(totalMap.get("land_outyearn")));
        toMapForStr(totalMap,"tb_1",df4.format(tb_1));

        double tb_2 = 1-1/Math.pow(1+r,Double.valueOf(totalMap.get("land_outyear1")));
        toMapForStr(totalMap,"tb_2",df4.format(tb_2));

        double tb_3 = 1-1/Math.pow(1+r,Double.valueOf(totalMap.get("land_outyear2")));
        toMapForStr(totalMap,"tb_3",df4.format(tb_3));

        double tb_4 = 1-1/Math.pow(1+r,Double.valueOf(totalMap.get("land_outyear3")));
        toMapForStr(totalMap,"tb_4",df4.format(tb_4));


//       表12
        double a1 = Double.valueOf(totalMap.get("price_index13"))/Double.valueOf(totalMap.get("price_index14"));
        double a2 = Double.valueOf(totalMap.get("tb_1"))/Double.valueOf(totalMap.get("tb_2"));
        double a3 = Double.valueOf(totalMap.get("ra_n"))/Double.valueOf(totalMap.get("ra_n1"));
        double a4 = Double.valueOf(totalMap.get("fs_n"))/Double.valueOf(totalMap.get("fs_n1"));
        double a5 = Double.valueOf(totalMap.get("highway_n"))/Double.valueOf(totalMap.get("highway_n1"));
        double a6 = Double.valueOf(totalMap.get("icd_n"))/Double.valueOf(totalMap.get("icd_n1"));
        double a7 = Double.valueOf(totalMap.get("land_mjn"))/Double.valueOf(totalMap.get("landn_mj1"));
        double a8 = Double.valueOf(totalMap.get("shape_n"))/Double.valueOf(totalMap.get("shape_n1"));
        double a9 = Double.valueOf(totalMap.get("sr_n"))/Double.valueOf(totalMap.get("sr_n1"));
        double a10 = Double.valueOf(totalMap.get("src_n"))/Double.valueOf(totalMap.get("src_n1"));
        double xiu_zheng1 = a1*a2*a3*a4*a5*a6*a7*a8*a9*a10;
        double bz_price1 = Double.valueOf(totalMap.get("land_money1")) *xiu_zheng1;

        double c1 = Double.valueOf(totalMap.get("price_index13"))/Double.valueOf(totalMap.get("price_index15"));
        double c2 = Double.valueOf(totalMap.get("tb_1"))/Double.valueOf(totalMap.get("tb_3"));
        double c3 = Double.valueOf(totalMap.get("ra_n"))/Double.valueOf(totalMap.get("ra_n2"));
        double c4 = Double.valueOf(totalMap.get("fs_n"))/Double.valueOf(totalMap.get("fs_n2"));
        double c5 = Double.valueOf(totalMap.get("highway_n"))/Double.valueOf(totalMap.get("highway_n2"));
        double c6 = Double.valueOf(totalMap.get("icd_n"))/Double.valueOf(totalMap.get("icd_n2"));
        double c7 = Double.valueOf(totalMap.get("land_mjn"))/Double.valueOf(totalMap.get("landn_mj2"));
        double c8 = Double.valueOf(totalMap.get("shape_n"))/Double.valueOf(totalMap.get("shape_n2"));
        double c9 = Double.valueOf(totalMap.get("sr_n"))/Double.valueOf(totalMap.get("sr_n2"));
        double c10 = Double.valueOf(totalMap.get("src_n"))/Double.valueOf(totalMap.get("src_n2"));
        double xiu_zheng2 = c1*c2*c3*c4*c5*c6*c7*c8*c9*c10;
        double bz_price2 = Double.valueOf(totalMap.get("land_money2")) *xiu_zheng2;

        double d1 = Double.valueOf(totalMap.get("price_index13"))/Double.valueOf(totalMap.get("price_index14"));
        double d2 = Double.valueOf(totalMap.get("tb_1"))/Double.valueOf(totalMap.get("tb_4"));
        double d3 = Double.valueOf(totalMap.get("ra_n"))/Double.valueOf(totalMap.get("ra_n3"));
        double d4 = Double.valueOf(totalMap.get("fs_n"))/Double.valueOf(totalMap.get("fs_n3"));
        double d5 = Double.valueOf(totalMap.get("highway_n"))/Double.valueOf(totalMap.get("highway_n3"));
        double d6 = Double.valueOf(totalMap.get("icd_n"))/Double.valueOf(totalMap.get("icd_n3"));
        double d7 = Double.valueOf(totalMap.get("land_mjn"))/Double.valueOf(totalMap.get("landn_mj3"));
        double d8 = Double.valueOf(totalMap.get("shape_n"))/Double.valueOf(totalMap.get("shape_n3"));
        double d9 = Double.valueOf(totalMap.get("sr_n"))/Double.valueOf(totalMap.get("sr_n3"));
        double d10 = Double.valueOf(totalMap.get("src_n"))/Double.valueOf(totalMap.get("src_n3"));
        double xiu_zheng3 = d1*d2*d3*d4*d5*d6*d7*d8*d9*d10;
        double bz_price3 = Double.valueOf(totalMap.get("land_money3")) *xiu_zheng3;

        double bz_price4 = (bz_price1+bz_price2+bz_price3)/3;

        toMapForStr(totalMap,"xiu_zheng1",df4.format(xiu_zheng1));
        toMapForStr(totalMap,"xiu_zheng2",df4.format(xiu_zheng2));
        toMapForStr(totalMap,"xiu_zheng3",df4.format(xiu_zheng3));
        toMapForStr(totalMap,"bz_price1",df4.format(bz_price1));
        toMapForStr(totalMap,"bz_price2",df4.format(bz_price2));
        toMapForStr(totalMap,"bz_price3",df4.format(bz_price3));
        toMapForStr(totalMap,"bz_price4",df4.format(bz_price4));


        double price_index_out = Double.valueOf(totalMap.get("price_index_last"))/Double.valueOf(totalMap.get("price_index_next"));
        totalMap.put("price_index_out",df4.format(price_index_out));

        //${land_money}×（1+${tb16_sum}）×100%×${k2}×${price_index_out}-${tab19_xiuzheng}=${tab20_dj}
        double tab20_dj =  Double.valueOf(totalMap.get("land_money"))*(1+tb16_sum) * k2 * price_index_out - tab19_xiuzheng;
        totalMap.put("tab20_dj", df4.format(tab20_dj));
        double dj_true = (bz_price4+tab20_dj)/2;
        totalMap.put("dj_true", df4.format(dj_true));
        double total_price = Double.valueOf(totalMap.get("land_mj")) * dj_true;
        totalMap.put("total_price", df4.format(total_price));

        DecimalFormat df2= new DecimalFormat("#########0.00");
        double bai=Double.valueOf(df2.format(total_price));
        totalMap.put("total_price1", MoneyToChiness.moneyToChinese(new BigDecimal(bai*10000)));

        toMap(totalMap, tid.getOthers(), "");


//        ApplicationHome h = new ApplicationHome(getClass());
//        String dirPath = h.getSource().getParentFile().toString();

        String bastPath = System.getProperty("user.dir");
        String srcPath  = bastPath+"\\src\\main\\resources\\word\\市场比较及基准地价.docx";

//        String srcPath  = "/home/tdbg/docm/市场比较及基准地价.docx";
        String destPath = bastPath+"\\src\\main\\resources\\word\\newword\\temp.docx"; //替换后保存的地址

        System.out.println(srcPath);
        if (wordflag) {
            WordUtils.allwrite(srcPath,destPath,wordMap(totalMap));
          return FileUtil.downloadFile(new File(destPath));
        }
        return wordMap(totalMap);
    }


    Map<String,String> toMap(Map<String,String> totalMap, Map<String,Object> map, String IndexNo){
        if (map != null && map.size() > 0){
            for (String key : map.keySet()) {
                if (IndexNo.length()>0)
                {
                    String keytemp=key.concat(IndexNo);
//                    totalMap.put(keytemp,map.get(key).toString());
                    totalMap.put("${".concat(keytemp).concat("}"),map.get(key).toString());
//                    totalMap.put("${".concat(keytemp),map.get(key).toString());
//                    totalMap.put(keytemp.concat("}"),map.get(key).toString());

                }else {
                    totalMap.put(key,map.get(key).toString());
//                    totalMap.put("${".concat(key).concat("}"),map.get(key).toString());
//                    totalMap.put("${".concat(key),map.get(key).toString());
//                    totalMap.put(key.concat("}"),map.get(key).toString());
                }
                //容错处理

            }
        }

        return totalMap;
    }

    Map<String,String> wordMap(Map<String,String> totalMap){
        Map<String,String> totalMapnew  = new HashMap<String,String> ();
            for (String key : totalMap.keySet()) {
                totalMapnew.put("${".concat(key).concat("}"),totalMap.get(key));
             }
        return totalMapnew;
    }



    Map<String,String> toMapForStr(Map<String,String> totalMap,String k,Object obj){
                //容错处理
                 String v =String.valueOf(obj);
                totalMap.put(k,v);
//                totalMap.put("${".concat(k).concat("}"),v);
//                totalMap.put("${".concat(k),v);
//                totalMap.put(k.concat("}"),v);

        return totalMap;
    }

    public static void main(String[] args) throws ParseException {
        String regEx="[^\\d.\\d]";
        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher("距宿州火车站约28.3公里");
        double fs_n_init = Double.valueOf(m.replaceAll("").trim());
//        java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("yyyy-MM-dd");
//
//        java.util.Date beginDate= format.parse("2007-12-24");
//
//        java.util.Date endDate= format.parse("2038-12-25");
//
//        long day=(endDate.getTime()-beginDate.getTime())/(24*60*60*1000);
//
//        System.out.println(yearCompare(beginDate,endDate));

        //2.计算2
        //        K2＝{1－[1/（1+r）m] }/{1－[1/（1+r）n] }=#k2#。
//        Double r = 5.4;
//        int n=50;
//        double m = Double.valueOf("2.56");
//
//        double K2 = (1-(1 / Math.pow(1 + r, m)) )/(1- (1 / Math.pow(1 + r, n)));
//        //返回2位小数，并且四舍五入
//        DecimalFormat df = new DecimalFormat("######0.0000");

    }

    */
/**
     * 计算2个日期相差多少年
     *
     * 列：2011-02-02  ~  2017-03-02 大约相差 6.1 年
     * @param fromDate
     * @param toDate
     * @return
     *//*

    public static String yearCompare(Date fromDate,Date toDate){
        DayCompare result = dayComparePrecise(fromDate, toDate);
        double month = result.getMonth();
        double year = result.getYear();
        double day  = result.getDay();
        //返回2位小数，并且四舍五入
        DecimalFormat df = new DecimalFormat("######0.00");
        return df.format(Math.abs(year + month / 12 +day/365));
    }

    */
/**
     * 计算2个日期之间相差的  相差多少年月日
     * 比如：2011-02-02 到  2017-03-02 相差 6年，1个月，0天
     * @param fromDate
     * @param toDate
     * @return
     *//*

    public static DayCompare dayComparePrecise(Date fromDate,Date toDate){
        Calendar from  =  Calendar.getInstance();
        from.setTime(fromDate);
        Calendar  to  =  Calendar.getInstance();
        to.setTime(toDate);

        int fromYear = from.get(Calendar.YEAR);
        int fromMonth = from.get(Calendar.MONTH);
        int fromDay = from.get(Calendar.DAY_OF_MONTH);

        int toYear = to.get(Calendar.YEAR);
        int toMonth = to.get(Calendar.MONTH);
        int toDay = to.get(Calendar.DAY_OF_MONTH);
        int year = toYear  -  fromYear;
        int month = toMonth  - fromMonth;
        int day = toDay  - fromDay;
        DayCompare dayCompare = new DayCompare();
        dayCompare.setYear(year);
        dayCompare.setMonth(month);
        dayCompare.setDay(day);
        return dayCompare;
    }


    */
/**
     * 计算级别
     * @param mater
     * @return
     *//*


    private int getJb(Map mater,String key){
        switch (key){
            case "ra_n"://1
                String ra_des[] ="主干道为主、道路通达性优，主干道与次干道并重、道路通达性较优，次干道为主、道路通达性一般，次干道与支路并重、道路通达性较劣，支路为主、道路通达性劣".split(",");
                for (int i = 0;i<ra_des.length;i++){
                    if (ra_des[i].contains(mater.get("ra_des").toString())){
                        return i;
                    }
                }
            case "fs_n"://2
                String regEx="[^\\d.\\d]";
                Pattern p = Pattern.compile(regEx);
                int jb =1;
                if (mater.get("fs_des") != null){
                    Matcher m = p.matcher(mater.get("fs_des").toString());
                    double fs_n_init = Double.valueOf(m.replaceAll("").trim());
                    if (fs_n_init <=10){
                        jb =1;
                    } else if (fs_n_init >10 && fs_n_init<=15){
                        jb =2;
                    }else if (fs_n_init >15 && fs_n_init<=20){
                        jb =3;
                    }else if (fs_n_init >20 && fs_n_init<=25){
                        jb =4;
                    }else {
                        jb =5;
                    }
                }
                return jb;
            case "highway_n"://3
                String regEx1="[^\\d.\\d]";
                Pattern p1 = Pattern.compile(regEx1);
                Matcher m2 = p1.matcher(mater.get("highway_des").toString());
                double highway_n = Double.valueOf(m2.replaceAll("").trim());

                int jibie =1;
                if (highway_n <=3){
                    jibie =1;
                } else if (highway_n >3 && highway_n<=5){
                    jibie =2;
                }else if (highway_n >5 && highway_n<=8){
                    jibie =3;
                }else if (highway_n >8 && highway_n<=12){
                    jibie =4;
                }else {
                    jibie =5;
                }
                return jibie;
            case "icd_n"://4
               String icd_n[] = "工业企业众多，产业集聚度高；工业企业较多，产业集聚度较高；工业企业数量一般，产业集聚度一般；工业企业较少，产业集聚度较低；工业企业少，无产业集聚、产业集聚度低".split("；");
                for (int i = 0;i<icd_n.length;i++){
                    if (icd_n[i].contains(mater.get("icd_des").toString())){
                        return i;
                    }
                }
                break;
            case "land_mjn":
                String ln[] ="面积适宜、对土地利用有利，面积较适宜、对土地利用较有利，面积一般、对土地利用基本无影响，面积较大或较小、对土地利用较为不利，面积过大或过小、对土地利用不利".split("，");

                for (int i = 0;i<ln.length;i++){
                    if (ln[i].contains(mater.get("area_des").toString())){
                        return i;
                    }
                }
                break;
            case "shape_n":
                String sh[] ="规则、对土地利用有利，较规则、对土地利用较有利；基本规则、对土地利用基本无影响，较不规则、对土地利用有一定不利影响，不规则、对土地利用影响大".split("，");

                for (int i = 0;i<sh.length;i++){
                    if (sh[i].contains(mater.get("shape_des").toString())){
                        return i;
                    }
                }
                break;
            case "sr_n":
                String sr[] ="临交通型主干道、临混合型主干道、临生活型主干道或交通型次干道、临生活型次干道、临支路".split("、");

                for (int i = 0;i<sr.length;i++){
                    if (sr[i].contains(mater.get("sr_des").toString())){
                        return i;
                    }
                }
                break;
            case "src_n":
                String src_des[] ="四面临路、三面临路、二面临路、一面临路、不直接临路".split("、");
                for (int i = 0;i<src_des.length;i++){
                    if (src_des[i].contains(mater.get("src_des").toString())){
                        return i;
                    }
                }
                break;
        }

        return 1;
    }



}
*/
